#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    vector<int> findAnagrams(string s, string p)
    {
        vector<int> diff(26, 0);
        int arr = 0;
        for (auto c : p)
        {
            if (diff[c - 'a']++ == 0)
                arr++;
        }
        vector<int> ans;
        int n = s.size();
        int ws = p.size();
        if (ws > n)
        {
            return ans;
        }
        for (int i = 0; i < ws; ++i)
        {
            if (diff[s[i] - 'a']-- == 0)
                ++arr;
            else if (diff[s[i] - 'a'] == 0)
                --arr;
        }
        if (arr == 0)
        {
            ans.push_back(0);
        }
        for (int i = 1; i <= n - ws; ++i)
        {
            if (++diff[s[i - 1] - 'a'] == 0)
                --arr;
            else if (diff[s[i - 1] - 'a'] == 1)
                ++arr;
            if (diff[s[i + ws - 1] - 'a']-- == 0)
                ++arr;
            else if (diff[s[i + ws - 1] - 'a'] == 0)
                --arr;

            if (arr == 0)
                ans.push_back(i);
        }
        return ans;
    }
};

int main()
{

    // system("pause");
    return 0;
}
